package com.ht.baselibs.utils;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.ht.baselibs.R;
import com.ht.baselibs.ui.dialog.LoadingDialog;

public class DialogUtils {
    public static Dialog showLoadingDialog(Activity act) {
        LoadingDialog loadingDialog = new LoadingDialog(act);
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.setCancelable(false);
        return loadingDialog;
    }

    /**
     * 从底部出来的，没有完全遮盖activity的dialog
     *
     * @param view
     * @param act
     * @return
     */
    public static Dialog showDialog(Activity act, View view) {
        final Dialog dialog = new Dialog(act, R.style.bottom_in_style_fullwidth);
        dialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        Window window = dialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.bottom_in_out_animaation);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = act.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        dialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        dialog.setCanceledOnTouchOutside(true);
        return dialog;
    }



}